/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package action.admin.FAQ;

import beans.FAQbean;
import dao.FAQ;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "createFAQ", urlPatterns = {"/createFAQ"})
public class createFAQ extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String question = request.getParameter("question");
            String answer = request.getParameter("answer");
            FAQbean faqBean = new FAQbean();
            faqBean.setFaq_question(question);
            faqBean.setFaq_answer(answer);
            FAQ faq = new FAQ();
            String msg = "";
            String error = "";
            if (!question.equals("") && question != null) {
                if (faq.createFAQ(faqBean)) {
                    msg = "Create successfull !";
                    request.setAttribute("msg", msg);
                    RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=faq");
                    rd.forward(request, response);
                } else {
                    error = "Create fail !";
                    request.setAttribute("error", error);
                    RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=create_FAQ");
                    rd.forward(request, response);
                }
            } else {
                error = "Insert question !";
                request.setAttribute("error", error);
                RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=create_FAQ");
                rd.forward(request, response);
            }
        } catch (Exception e) {
        }
    }

}
